/*
 * @Date: 2022-07-30 10:58:50
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-08-11 14:17:33
 * @FilePath: \archives-fe\src\view\appraisalAndDisposition\Destruction\reducers\DestructionReducer.js
 */
import { editItemById } from '@/utils/list';
import { APPROVAL, CHOICE, INCHOICE } from '../constants';
export const DestructionReducer = (state, action) => {
  switch (action.type) {
    case APPROVAL: {
      console.log('TODO', state.List);
      return {
        ...state,
        List: editItemById(action.data.id, action.data, state.List),
        appraisalList: editItemById(action.data.id, action.data, state.appraisalList),
        operateList: editItemById(action.data.id, action.data, state.operateList)
      };
    }

    case CHOICE: {
      const ToDoList = JSON.parse(JSON.stringify(state.List));
      let newArr = [];
      if (action.data === 'all') {
        newArr = ToDoList;
      } else if (action.data === 'wait') {
        newArr = ToDoList.filter((item) => {
          return item.state === 0;
        });
      } else if (action.data === 'audit') {
        newArr = ToDoList.filter((item) => {
          return item.state === 1 || item.state === 2;
        });
      } else if (action.data === 'success') {
        newArr = ToDoList.filter((item) => {
          return item.state === 1;
        });
      } else {
        newArr = ToDoList.filter((item) => {
          return item.state === 2;
        });
      }
      return {
        ...state,
        sidebar: action.data,
        appraisalList: newArr
      };
    }
    case INCHOICE: {
      const ToDoList = JSON.parse(JSON.stringify(state.appraisalList));
      let newArr = [];
      if (action.data === 'all') {
        newArr = ToDoList;
      } else if (action.data === '1') {
        newArr = ToDoList.filter((item) => {
          return item.dossier === '全宗1';
        });
      } else if (action.data === '2') {
        newArr = ToDoList.filter((item) => {
          return item.dossier === '全宗2';
        });
      } else if (action.data === '3') {
        newArr = ToDoList.filter((item) => {
          return item.dossier === '全宗3';
        });
      }
      return {
        ...state,
        operateList: newArr
      };
    }

    default:
      console.log('untouched', action);
      return state;
  }
};
